package power

import (
	"context"
	"time"

	"go-weixin/app/usercenter/api/internal/svc"
	"go-weixin/app/usercenter/api/internal/types"
	"go-weixin/app/usercenter/rpc/pb/proto/usercenter"

	"github.com/zeromicro/go-zero/core/logx"
)

type PowerAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewPowerAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PowerAddLogic {
	return &PowerAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *PowerAddLogic) PowerAdd(req *types.PowerAddReq) (resp *types.PowerAddResp, err error) {
	// ctx, canelFunc := context.WithTimeout(context.Background(), 5*time.Second)
	// defer canelFunc()
	ctx, canelFunc := context.WithTimeout(context.Background(), 5*time.Second)
	defer canelFunc()
	_, err = l.svcCtx.UserRpc.PowerAdd(ctx, &usercenter.PowerAddReq{
		Name:     req.Name,
		Method:   req.Method,
		Url:      req.Url,
		ParentId: req.ParentId,
	})
	return
}
